// pages/join/join.js
const app = getApp()
var postLogin = require("../../utils/wh.js");
var WxParse = require('../../wxParse/wxParse.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    navList:[
      { tit: '城市经理加盟'},
      { tit: '合作司机加盟'},
      { tit: '人才招聘'} 
    ],
    currentTab:0,
    modal: false,
    // windowHeight:'',
    name: '',
    phone: '',
    remark: '',
    cityMan:'',
    driver:'',
    talents:''

  },
  selectNav:function(e){
    this.setData({
      currentTab: e.currentTarget.dataset.index
    })
  },
  joinBtn:function(){
    this.setData({
      modal: true
    })
  },
  close: function () {
    this.setData({
      modal: false
    })
  },
  // windowHeight:function(){
  //   let that=this
  //   wx.getSystemInfo({
  //     success: function (res) {
  //       console.log(res.windowHeight)
  //       that.setData({
  //         windowHeight:res.windowHeight
  //       })
  //     }
  //   })
  // },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
this.loop()
  },
  loop: function () {
    var that = this;
    // var code = app.globalData.code;
    // if (!code) {
    //   var that = this
    //   setTimeout(function () { that.loop(); }, 100)
    // } else {
    //   that.setData({
    //     code: code,
    //   })
      var postUrl = '/api/company.transport/get_content',
        cityMan = {
          type: 1
        },
      driver = {
          type: 2
        },
      talents = {
          type: 3
        };
      postLogin.Post(postUrl, cityMan, that.cityMan);
      postLogin.Post(postUrl, driver, that.driver);
      postLogin.Post(postUrl, talents, that.talents);
    // }
  },
  cityMan: function (res) {
    console.log('cityMan',res)
    let that = this;
    var list = res;
    wx.hideLoading();
    var article = res.content,
    title=res.title;
    WxParse.wxParse('cityMan_article', 'html', article, this);
    WxParse.wxParse('cityMan_title', 'html', title, this);
    that.setData({
      cityMan: list,
    })
  },
  driver: function (res) {
    console.log(res)
    let that = this;
    var list = res;
    wx.hideLoading();
    var article = res.content,
    title=res.title;
    WxParse.wxParse('driver_article', 'html', article, this);
    WxParse.wxParse('driver_title', 'html', title, this);
    that.setData({
      driver: list,
    })
  },
  talents: function (res) {
    console.log(res)
    let that = this;
    var list = res;
    wx.hideLoading();
    var article = res.content,
    title=res.title;
    WxParse.wxParse('talents_article', 'html', article, this);
    WxParse.wxParse('talents_title', 'html', title, this);
    that.setData({
      talents: list,
    })
  },
  // 立即预约
  bindName: function (e) {
    this.setData({
      name: e.detail.value
    })
  },
  bindPhone: function (e) {
    this.setData({
      phone: e.detail.value
    })
  },
  bindRemark: function (e) {
    this.setData({
      remark: e.detail.value
    })
  },
  submitContent: function () {
    var name = this.data.name;
    var phone = this.data.phone;
    var remark = this.data.remark;
    let idx = this.data.currentTab, 
      status_name=3;
    if (!name || !phone) {
      wx.showToast({
        title: '请填写完整信息',
        icon: "none"
      })
      return false;
    }
    if (!(/^1[34578]\d{9}$/.test(phone))) {
      wx.showToast({
        title: '手机号格式错误',
        icon: "none"
      })
      return false;
    }
    switch (parseInt(idx)) {
      case 0:
        status_name = 3;
        break;
      case 1:
        status_name = 4;
        break;
    }
    var postUrl = '/api/company.transport/order',
      postData = {
        type: status_name,
        name: this.data.name,
        mobile: this.data.phone,
        remark: this.data.remark,
      };
    postLogin.Post(postUrl, postData, this.submitsuccess);
  },
  submitsuccess: function () {
    wx.showToast({
      title: '提交成功',
      complete: function () {
        setTimeout(function () {
          wx.switchTab({
            url: '../index/index'
          })
        }, 2000);
      }
    })

    return;
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    app.app_auth(this)
  this.setData({
    currentTab: 0,
    modal: false,
    name: '',
    phone: '',
    remark: ''
  })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})